#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@IDE     ：PyCharm 
@Author  ：kiway
@Date    ：2024/7/27 8:53 
"""

import json

import yaml

try:
    with open('config.yml', 'r', encoding='utf-8') as f:
        result = yaml.load(f.read(), Loader=yaml.FullLoader)

except Exception as e:
    raise ValueError("配置文件读取有误,需要为‘config.yml’")


class Config:

    def __init__(self):
        self.all_config: dict = None
        self.read_config()
        self.sandbox_mode = result["sandbox_mode"]
        self.leverage = result["leverage"]
        self.buffer_balance_ratio = result["buffer_balance_ratio"]
        self.mq_port = result["mq_port"]
        self.max_num_pipe = result["max_num_pipe"]
        self.exchange_id = result["exchange_id"]
        self.maker2taker_delay = result["maker2taker_delay"]

    def read_config(self):
        f = open(result["exchange_config"]["path"], "r")
        self.all_config = json.load(f)
        f.close()

    @property
    def config(self):
        if self.sandbox_mode:

            return self.all_config["test"]

        else:
            return self.all_config["live"]

    @property
    def exchange_apikey(self):
        return self.config["apiKey"]

    @property
    def exchange_secret(self):
        return self.config["secret"]

    @property
    def exchange_options(self):
        return self.config["options"]


config = Config()
